package org.jeecg.modules.cusorder.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.cusorder.entity.CusOrderInfo;
import org.jeecg.modules.cusstyle.entity.CusStyleInfo;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: 订单信息
 * @Date:   2021-09-10
 * @Version: V1.0
 */
public interface CusOrderInfoMapper extends BaseMapper<CusOrderInfo> {
	/**
	 * 通过成色ID查询成色名称
	 * @param goldKaratId
	 * @return
	 */
	@Select("select gold_karat_name from gold_karat where id = #{goldKaratId} ")
	public String getGoldKaratName(@Param("goldKaratId") String goldKaratId);

	/**
	 * 通过订单ID查询选款数量
	 * @param id
	 * @return
	 */
	@Select("select count(*) from style_customer_info where order_info_id = #{orderInfoId} ")
	public Integer countAllOrderStyle(@Param("orderInfoId") String orderInfoId);
	
	/**
	 * 通过订单ID查询款式转生产单的数量
	 * @param id
	 * @return
	 */
	@Select("select count(*) from style_customer_info where order_info_id = #{orderInfoId} and is_convert = 1")
	public Integer countConvertedOrderStyle(@Param("orderInfoId") String orderInfoId);
	
	/**
	 * 通过订单ID查询款式开工单的数量
	 * @param id
	 * @return
	 */
	@Select("select count(*) from style_customer_info where order_info_id = #{orderInfoId} and is_open = 1")
	public Integer countOpenedOrderStyle(@Param("orderInfoId") String orderInfoId);

	/**
	 * 根据订单ID查询客户款式列表
	 * @param orderId
	 * @return
	 */
	@Select("select * from style_customer_info where order_info_id = #{orderInfoId}")
	public List<CusStyleInfo> getCusStyleInfoListByOrderId(@Param("orderInfoId") String orderInfoId);

	/**
	 * 批量取消订单
	 * @param idsList
	 * @param status（1部分取消 2整单取消）
	 */
	@Delete("<script>"
			+ "UPDATE order_info SET order_cancel = #{status} WHERE id IN "
			+ "<foreach item='item' index='index' collection='idsList' open='(' separator=',' close=')'>"
			+ "#{item}"
            + "</foreach>"
            + "</script>")
	public void cancelByIds(@Param("idsList") List<String> idsList, @Param("status") String status);
}
